package com.youlv.yl.controller;

import com.youlv.yl.aop.ParamCheck;
import com.youlv.yl.bo.UserNameLoginBo;
import com.youlv.yl.bo.UserPhoneLoginBo;
import com.youlv.yl.config.SystemConfig;
import com.youlv.yl.dto.UserAddDto;
import com.youlv.yl.service.intf.UserService;
import com.youlv.yl.vo.R;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author fenghe
 * @since 2022-01-02
 */
@RestController
@RequestMapping("/yl/user/")
@Api(value = "实现注册登陆的相关操作", tags = "实现注册登录的相关操作")
/**  跨域*/
@CrossOrigin
public class UserController {
    @Autowired
    private UserService service;

    @PostMapping("register.do")
    /** 手机号注册并登录*/
    public R register(@RequestBody UserAddDto dto, HttpServletRequest request) {
        return service.register(dto, request.getRemoteAddr());
    }

    @PostMapping("phoneLogin.do")
    /** 手机号登陆*/
    public R phoneLogin(@RequestBody UserPhoneLoginBo bo, HttpServletRequest request) {
        return service.login(bo, request.getRemoteAddr());
    }

    @PostMapping("nameLogin.do")
    /** 用户名登陆*/
    public R nameLogin(@RequestBody(required = false) UserNameLoginBo bo, HttpServletRequest request) {
        return service.login(bo, request.getRemoteAddr());
    }

    @PostMapping("findPassword.do")
    /** 密码找回*/
    public R findPassword(@RequestBody UserAddDto dto, HttpServletRequest request) {
        return service.findPassword(dto, request.getRemoteAddr());
    }

    @GetMapping("loginOut.do")
    public R loginOut(HttpServletRequest request) {
        String token = request.getHeader(SystemConfig.REQ_HEADER_TOKEN);
        return service.loginOut(token);
    }
}
